﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NutriStat.Statistics;
using NutriStat.Data;

namespace NutriStat
{
    /// <summary>
    /// The export/find form.
    /// </summary>
    public partial class FindRecordsDialogBase : NutriDialog
    {
        #region Data
        #region Protected Data
        #endregion Protected Data

        #region Private Data
        private FormBase menu;
        private IDbDriver db;
        private DataTable dt;
        private string selection;
        private bool isFindWindow;
        private bool isConfidential;
        private NutriConfig config;
        #endregion Private Data

        #region Internal Data
        #endregion Internal Data        
        #endregion Data

        #region Constructors
        public FindRecordsDialogBase()
        {
            InitializeComponent();
        }

        /// <summary>
        /// The export/find constructor
        /// </summary>
        public FindRecordsDialogBase(FormMainMenu callingMenu)
        {
            InitializeComponent();

            menu = callingMenu;

            //FileName = string.Empty;
            //FileExtension = string.Empty;
            Selection = string.Empty;
            IsFindWindow = false;
            IsConfidential = true;
        }

        /// <summary>
        /// The export/find constructor
        /// </summary>
        public FindRecordsDialogBase(FormMainMenu callingMenu, bool isFindWindow, NutriConfig mainConfig)
        {
            InitializeComponent();

            menu = callingMenu;

            //FileName = string.Empty;
            //FileExtension = string.Empty;
            Selection = string.Empty;
            IsFindWindow = isFindWindow;
            IsConfidential = true;

            config = new NutriConfig(mainConfig);
        }
        #endregion Constructors

        #region Properties
        #region Public Properties
        /// <summary>
        /// Gets/sets whether or not the display is that of a find window (search
        /// results) or an export window.
        /// </summary>
        public bool IsFindWindow
        {
            get
            {
                return isFindWindow;
            }
            set
            {
                isFindWindow = value;
            }
        }

        /// <summary>
        /// Gets/sets whether or not the display should be confidential (in other
        /// words, hide the identifying information such as names, address, etc).
        /// </summary>
        public bool IsConfidential
        {
            get
            {
                return isConfidential;
            }
            set
            {
                isConfidential = value;
            }
        }        

        /// <summary>
        /// Gets/sets the selection criteria
        /// </summary>
        public string Selection
        {
            get
            {
                return selection;
            }
            set
            {
                selection = value;
            }
        }
        #endregion Public Properties

        #region Protected Properties
        #endregion Protected Properties

        #region Private Properties
        #endregion Private Properties
        #endregion Properties

        #region Methods
        #region Public Methods
        #endregion Public Methods

        #region Protected Methods
        #endregion Protected Methods

        #region Private Methods
        /// <summary>
        /// Clears all form controls
        /// </summary>
        private void Clear()
        {
            Selection = string.Empty;

            checkBoxBMIFlag.Checked = false;
            checkBoxHAFlag.Checked = false;
            checkBoxWAFlag.Checked = false;
            checkBoxWHFlag.Checked = false;
            checkBoxConfidental.Checked = false;

            comboBoxDOM.Text = string.Empty;
            comboBoxSex.Text = string.Empty;

            dateTimePickerDOM1.Value = DateTime.Today;
            dateTimePickerDOM2.Value = DateTime.Today;

            textBoxAge.Text = string.Empty;
            textBoxAgeupper.Text = string.Empty;
            textBoxBMI.Text = string.Empty;
            textBoxBMIC.Text = string.Empty;
            textBoxBMICupper.Text = string.Empty;
            textBoxBMIupper.Text = string.Empty;
            textBoxBMIZ.Text = string.Empty;
            textBoxBMIZupper.Text = string.Empty;
            textBoxHead.Text = string.Empty;
            textBoxHeadC.Text = string.Empty;
            textBoxHeadCupper.Text = string.Empty;
            textBoxHeadupper.Text = string.Empty;
            textBoxHeadZ.Text = string.Empty;
            textBoxHeadZupper.Text = string.Empty;
            textBoxHeight.Text = string.Empty;
            textBoxHeightupper.Text = string.Empty;
            textBoxHTAgeC.Text = string.Empty;
            textBoxHTAgeCupper.Text = string.Empty;
            textBoxHTAgeZ.Text = string.Empty;
            textBoxHTAgeZupper.Text = string.Empty;
            textBoxID.Text = string.Empty;
            textBoxIDupper.Text = string.Empty;
            textBoxLastname.Text = string.Empty;
            textBoxMUAC.Text = string.Empty;
            textBoxMUACupper.Text = string.Empty;
            textBoxMUACZAge.Text = string.Empty;
            textBoxMUACZAgeupper.Text = string.Empty;
            textBoxMUACZHeight.Text = string.Empty;
            textBoxMUACZHeightupper.Text = string.Empty;
            textBoxWeight.Text = string.Empty;
            textBoxWeightupper.Text = string.Empty;
            textBoxWTAgeC.Text = string.Empty;
            textBoxWTAgeCupper.Text = string.Empty;
            textBoxWTAgeZ.Text = string.Empty;
            textBoxWTAgeZupper.Text = string.Empty;
            textBoxWTHeightC.Text = string.Empty;
            textBoxWTHeightCupper.Text = string.Empty;
            textBoxWTHeightZ.Text = string.Empty;
            textBoxWTHeightZupper.Text = string.Empty;
            textBoxSSF.Text = string.Empty;
            textBoxSSFUpper.Text = string.Empty;
            textBoxTSF.Text = string.Empty;
            textBoxTSFUpper.Text = string.Empty;
            textBoxSSFZ.Text = string.Empty;
            textBoxSSFZupper.Text = string.Empty;
            textBoxTSFZ.Text = string.Empty;
            textBoxTSFZupper.Text = string.Empty;
        }

        /// <summary>
        /// Creates a selection string used for selecting records from the database.
        /// </summary>
        private bool CreateSelection()
        {
            // TODO: Reform this, we don't want SQL on the UI if we can help it! Look at using NutriDatabase object.
            string selection = " WHERE";

            try
            {
                int system = 1;// m_fMainMenu.GetMeasurementSystem(); // metric = 1, imperial = 0

                string size = "in";
                string weight = "lbs";

                if (system == 1)
                {
                    size = SharedStrings.CENTIMETERS_ABBR;
                    weight = "kilos";
                }

                string lower = string.Empty;
                string upper = string.Empty;

                /////////////////////////////////////////////////////////////////////
                //////// Selection of ID field
                /////////////////////////////////////////////////////////////////////
                lower = textBoxID.Text;
                upper = textBoxIDupper.Text;

                if (lower.Equals(string.Empty))
                {
                    lower = "0";
                    upper = Int32.MaxValue.ToString();
                    selection = selection + " fldIdNo >= " + lower + " AND fldIdNo <= " + upper;
                }
                else if (upper.Equals(string.Empty) && !lower.Equals(string.Empty))
                {
                    upper = lower;
                    selection = selection + " fldIdNo = " + upper;
                }
                else
                {
                    selection = selection + " fldIdNo >= " + lower + " AND fldIdNo <= " + upper;
                }

                /////////////////////////////////////////////////////////////////////
                //////// Selection of Lastname
                /////////////////////////////////////////////////////////////////////
                string lastName = textBoxLastname.Text;
                if (lastName != "")
                    selection = selection + " AND fldLastName = '" + lastName + "'";

                /////////////////////////////////////////////////////////////////////
                //////// Selection of Gender
                /////////////////////////////////////////////////////////////////////
                string gender = comboBoxSex.Text;
                if (gender.Equals("Male"))
                    selection = selection + " AND fldSex = 'M'";
                else if (gender.Equals("Female"))
                    selection = selection + " AND fldSex = 'F'";

                /////////////////////////////////////////////////////////////////////
                //////// Selection of Age (months)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxAge.Text;
                upper = textBoxAgeupper.Text;

                if (lower == "")
                {
                    //lower = "0";
                    //upper = Int32.MaxValue.ToString();
                    selection = selection + string.Empty;// +" AND fldAge >= " + lower + " AND fldAge <= " + upper;
                }
                else if (upper == "" && lower != "")
                {
                    upper = lower;
                    selection = selection + " AND fldAge = " + upper;
                }
                else
                {
                    selection = selection + " AND fldAge >= " + lower + " AND fldAge <= " + upper;
                }

                /////////////////////////////////////////////////////////////////////
                //////// Selection of Height
                /////////////////////////////////////////////////////////////////////
                lower = textBoxHeight.Text;
                upper = textBoxHeightupper.Text;

                if (lower == "")
                {
                    //lower = "0";
                    //upper = Int32.MaxValue.ToString();
                    selection = selection + string.Empty;// +" AND fld" + size + " >= " + lower + " AND fld" + size + " <= " + upper;
                }
                else if (upper == "" && lower != "")
                {
                    upper = lower;
                    selection = selection + " AND fld" + size + " = " + upper;
                }
                else
                {
                    selection = selection + " AND fld" + size + " >= " + lower + " AND fld" + size + " <= " + upper;
                }

                /////////////////////////////////////////////////////////////////////
                //////// Selection of Weight
                /////////////////////////////////////////////////////////////////////
                lower = textBoxWeight.Text;
                upper = textBoxWeightupper.Text;

                if (lower == "")
                {
                    //lower = "0";
                    //upper = Int32.MaxValue.ToString();
                    selection = selection + string.Empty;// " AND fld" + weight + " >= " + lower + " AND fld" + weight + " <= " + upper;
                }
                else if (upper == "" && lower != "")
                {
                    upper = lower;
                    selection = selection + " AND fld" + weight + " = " + upper;
                }
                else
                {
                    selection = selection + " AND fld" + weight + " >= " + lower + " AND fld" + weight + " <= " + upper;
                }


                /////////////////////////////////////////////////////////////////////
                //////// Selection of Head circumference
                /////////////////////////////////////////////////////////////////////
                lower = textBoxHead.Text;
                upper = textBoxHeadupper.Text;

                if (lower == "")
                    selection = selection + string.Empty;// + " AND fld" + size + "HCircum >= " + lower + " AND fld" + size + "HCircum <= " + upper;                
                else if (upper == "" && lower != "")
                {
                    upper = lower;
                    selection = selection + " AND fld" + size + "HCircum = " + upper;
                }
                else
                {
                    selection = selection + " AND fld" + size + "HCircum >= " + lower + " AND fld" + size + "HCircum <= " + upper;
                }


                /////////////////////////////////////////////////////////////////////
                //////// Selection of MUAC
                /////////////////////////////////////////////////////////////////////
                lower = textBoxMUAC.Text;
                upper = textBoxMUACupper.Text;

                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fld" + size + "MUAC = " + lower;
                else
                    selection = selection + " AND fld" + size + "MUAC >= " + lower + " AND fld" + size + "MUAC <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of BMI (raw)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxBMI.Text;
                upper = textBoxBMIupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;// + " AND fldBMI >= " + Int32.MinValue.ToString() + " AND fldBMI <= " + Int32.MaxValue.ToString();                
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldBMI = " + lower;
                else
                    selection = selection + " AND fldBMI >= " + lower + " AND fldBMI <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of BMI (z-score)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxBMIZ.Text;
                upper = textBoxBMIZupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldBMIZ = " + lower;
                else
                    selection = selection + " AND fldBMIZ >= " + lower + " AND fldBMIZ <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of BMI (percentile)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxBMIC.Text;
                upper = textBoxBMICupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldBMIC = " + lower;
                else
                    selection = selection + " AND fldBMIC >= " + lower + " AND fldBMIC <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of Height-for-Age (z-score)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxHTAgeZ.Text;
                upper = textBoxHTAgeZupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldCDCHAZ = " + lower;
                else
                    selection = selection + " AND fldCDCHAZ >= " + lower + " AND fldCDCHAZ <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of Height-for-Age (C)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxHTAgeC.Text;
                upper = textBoxHTAgeCupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldCDCHAC = " + lower;
                else
                    selection = selection + " AND fldCDCHAC >= " + lower + " AND fldCDCHAC <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of Weight-for-Age (z-score)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxWTAgeZ.Text;
                upper = textBoxWTAgeZupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldCDCWAZ = " + lower;
                else
                    selection = selection + " AND fldCDCWAZ >= " + lower + " AND fldCDCWAZ <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of Weight-for-Age (C)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxWTAgeC.Text;
                upper = textBoxWTAgeCupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldCDCWAC = " + lower;
                else
                    selection = selection + " AND fldCDCWAC >= " + lower + " AND fldCDCWAC <= " + upper;



                /////////////////////////////////////////////////////////////////////
                //////// Selection of Weight-for-Height (z-score)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxWTHeightZ.Text;
                upper = textBoxWTHeightZupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldCDCWHZ = " + lower;
                else
                    selection = selection + " AND fldCDCWHZ >= " + lower + " AND fldCDCWHZ <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of Weight-for-Height (C)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxWTHeightC.Text;
                upper = textBoxWTHeightCupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldCDCWHC = " + lower;
                else
                    selection = selection + " AND fldCDCWHC >= " + lower + " AND fldCDCWHC <= " + upper;



                /////////////////////////////////////////////////////////////////////
                //////// Selection of Head circumference (z-score)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxHeadZ.Text;
                upper = textBoxHeadZupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldHCircumZ = " + lower;
                else
                    selection = selection + " AND fldHCircumZ >= " + lower + " AND fldHCircumZ <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of Head circumference (percentile)
                /////////////////////////////////////////////////////////////////////
                lower = textBoxHeadC.Text;
                upper = textBoxHeadCupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldHCircumC = " + lower;
                else
                    selection = selection + " AND fldHCircumC >= " + lower + " AND fldHCircumC <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of MUAC z-for-age
                /////////////////////////////////////////////////////////////////////
                lower = textBoxMUACZAge.Text;
                upper = textBoxMUACZAgeupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldMUACAgeZ = " + lower;
                else
                    selection = selection + " AND fldMUACAgeZ >= " + lower + " AND fldMUACAgeZ <= " + upper;


                /////////////////////////////////////////////////////////////////////
                //////// Selection of MUAC z-for-height
                /////////////////////////////////////////////////////////////////////
                lower = textBoxMUACZHeight.Text;
                upper = textBoxMUACZHeightupper.Text;
                if (lower == "")
                    selection = selection + string.Empty;
                else if (upper == "" && lower != "")
                    selection = selection + " AND fldMUACHeightZ = " + lower;
                else
                    selection = selection + " AND fldMUACHeightZ >= " + lower + " AND fldMUACHeightZ <= " + upper;

                /////////////////////////////////////////////////////////////////////
                //////// Selection of Flags
                /////////////////////////////////////////////////////////////////////
                if (checkBoxBMIFlag.Checked)
                    selection = selection + " AND (fldCDCBMIFlag < -4 OR fldCDCBMIFlag > 5)";

                if (checkBoxHAFlag.Checked)
                    selection = selection + " AND (fldCDCHAFlag < -5 OR fldCDCHAFlag > 3)";

                if (checkBoxWAFlag.Checked)
                    selection = selection + " AND (fldCDCWAFlag < -5 OR fldCDCWAFlag > 5)";

                if (checkBoxWHFlag.Checked)
                    selection = selection + " AND (fldCDCWHFlag < -4 OR fldCDCWHFlag > 5)";

                selection = selection + ";";

                Selection = selection;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }

            return true;
        }

        private bool ExportSetup()
        {
            // TODO: Redo this.

            return true;
        }

        /// <summary>
        /// Exports the current selection of records.
        /// </summary>
        private void Export()
        {
            
        }
        #endregion Private Methods
        #endregion Methods

        #region Event Handlers
        private void buttonClear_Click(object sender, EventArgs e)
        {
            this.Clear();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (!CreateSelection())
                return;

            if (!ExportSetup())
                return;

            Export();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonGrid_Click(object sender, EventArgs e)
        {
            if (!CreateSelection())
                return;            

            //m_fMainMenu.ShowGrid(GetConnectionString(), GetConnectionType(), GetTableName(), GetSelection());

            if (IsFindWindow)
            {
                this.Close();
            }

            /*
            GridViewForm grid;
            if(IsFindWindow())
                grid = new GridViewForm(GetConnectionString(), GetConnectionType(), GetTableName(), "SELECT * FROM " + GetTableName() + " " + GetSelection(), true, ref m_fMainMenu);
            else
                grid = new GridViewForm(GetConnectionString(), GetConnectionType(), GetTableName(), "SELECT * FROM " + GetTableName() + " " + GetSelection());

            grid.Show(this);
            
            //GridViewForm(string connection, string connectionType, string tableName, string selection)
            */
        }

        private void FormExportCustom_Load(object sender, EventArgs e)
        {
            groupBoxStats.Text = "Statistical Output - " + config.ReferenceType;
            checkBoxConfidental.Checked = IsConfidential;

            if (config.UnitsHeight == MeasurementUnits.Centimeter.Abbreviation)
                labelHeight.Text = "Height (" + MeasurementUnits.Centimeter.Abbreviation + ")";
            else
                labelHeight.Text = "Height (" + MeasurementUnits.Inch.Abbreviation + ")";

            if (config.UnitsWeight == MeasurementUnits.Kilogram.Abbreviation)
                labelWeight.Text = "Weight (" + MeasurementUnits.Kilogram.Abbreviation + ")";
            else
                labelWeight.Text = "Weight (" + MeasurementUnits.Pound.Abbreviation + ")";

            if (config.UnitsHead == MeasurementUnits.Centimeter.Abbreviation)
                labelHead.Text = "Head Circumference (" + MeasurementUnits.Centimeter.Abbreviation + ")";
            else
                labelHead.Text = "Head Circumference (" + MeasurementUnits.Inch.Abbreviation + ")";

            if (config.UnitsArm == MeasurementUnits.Centimeter.Abbreviation)
                labelMUAC.Text = "Mid-upper Arm Circumference (" + MeasurementUnits.Centimeter.Abbreviation + ")";
            else
                labelMUAC.Text = "Mid-upper Arm Circumference (" + MeasurementUnits.Inch.Abbreviation + ")";

            if (config.UnitsSkin == MeasurementUnits.Millimeter.Abbreviation) 
            {
                labelSSF.Text = "Subscapular skin fold (" + MeasurementUnits.Millimeter.Abbreviation + ")";
                labelTSF.Text = "Triceps skin fold (" + MeasurementUnits.Millimeter.Abbreviation + ")";
            }
            else 
            {
                labelSSF.Text = "Subscapular skin fold (" + MeasurementUnits.Inch.Abbreviation + ")";
                labelTSF.Text = "Triceps skin fold (" + MeasurementUnits.Inch.Abbreviation + ")";
            }

            if (config.ReferenceType == GrowthReferenceTypes.CDC2000)
            {
                textBoxSSFZ.Enabled = false;
                textBoxSSFC.Enabled = false;
                textBoxTSFZ.Enabled = false;
                textBoxTSFC.Enabled = false;
                textBoxMUACZ.Enabled = false;
                textBoxMUACC.Enabled = false;

                textBoxSSFZupper.Enabled = false;
                textBoxSSFCupper.Enabled = false;
                textBoxTSFZupper.Enabled = false;
                textBoxTSFCupper.Enabled = false;
                textBoxMUACZupper.Enabled = false;
                textBoxMUACCupper.Enabled = false;                
            }

            if (config.ReferenceType == GrowthReferenceTypes.WHO1978)
            {
                textBoxBMIZ.Enabled = false;
                textBoxBMIC.Enabled = false;
                textBoxHeadZ.Enabled = false;
                textBoxHeadC.Enabled = false;
                textBoxSSFZ.Enabled = false;
                textBoxSSFC.Enabled = false;
                textBoxTSFZ.Enabled = false;
                textBoxTSFC.Enabled = false;
                textBoxMUACZ.Enabled = false;
                textBoxMUACC.Enabled = false;

                textBoxBMIZupper.Enabled = false;
                textBoxBMICupper.Enabled = false;
                textBoxHeadZupper.Enabled = false;
                textBoxHeadCupper.Enabled = false;
                textBoxSSFZupper.Enabled = false;
                textBoxSSFCupper.Enabled = false;
                textBoxTSFZupper.Enabled = false;
                textBoxTSFCupper.Enabled = false;
                textBoxMUACZupper.Enabled = false;
                textBoxMUACCupper.Enabled = false;
            }

            if (IsFindWindow)
            {
                buttonOK.Visible = false;          
                buttonGrid.Text = "Find";
                Point cancel = buttonCancel.Location;
                Point grid = buttonGrid.Location;

                buttonCancel.Location = grid;
                buttonGrid.Location = cancel;

                buttonCancel.TabIndex = 102;
                buttonGrid.TabIndex = 101;                

                this.AcceptButton = buttonGrid;
                this.Text = "Find Records";
                
                labelTitle.Text = "Enter criteria by which to find records.";
            }
        }

        private void checkBoxConfidental_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxConfidental.Checked)
                IsConfidential = true;
            else
                IsConfidential = false;
        }
        #endregion Event Handlers

        private void comboBoxDOM_SelectedIndexChanged(object sender, EventArgs e)
        {            
            if (comboBoxDOM.Text.Contains("between"))
            {                
                dateTimePickerDOM1.Enabled = true;
                dateTimePickerDOM2.Enabled = true;
            }
            else if (comboBoxDOM.Text.Contains("greater than") || comboBoxDOM.Text.Contains("less than") ||
                comboBoxDOM.Text.Contains("Equals"))
            {
                dateTimePickerDOM1.Enabled = true;
                dateTimePickerDOM2.Enabled = false;
            }            
            else
            {
                dateTimePickerDOM1.Enabled = false;
                dateTimePickerDOM2.Enabled = false;
            }
        }

    }
}
